import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)
        
        toolBar=QToolBar()
        toolBar.addWidget(QLabel('Mode'))
        cb=QComboBox()
        cb.addItems(QLCDNumber.Mode.__members__.keys())
        cb.currentTextChanged.connect(self.OnModeChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('SegmentStyle'))
        cb=QComboBox()
        cb.addItems(QLCDNumber.SegmentStyle.__members__.keys())
        cb.currentTextChanged.connect(self.OnSegmentStyleChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('DigitCount:'))
        self.count=QLineEdit()
        self.count.editingFinished.connect(self.OnDigitCountChanged)
        toolBar.addWidget(self.count)

        toolBar.addWidget(QLabel('DisplayText:'))
        self.text=QLineEdit()
        self.text.editingFinished.connect(self.OnDisplayTextChanged)
        toolBar.addWidget(self.text)        

        layout.addWidget(toolBar)

        self.lcd=QLCDNumber()
        layout.addWidget(self.lcd)

        self.timelcd=QLCDNumber()
        self.timelcd.setMode(QLCDNumber.Mode.Dec)
        self.timelcd.setSegmentStyle(QLCDNumber.SegmentStyle.Flat)
        self.timelcd.setDigitCount(20)
        layout.addWidget(self.timelcd)

        timer=QTimer(self)        
        timer.timeout.connect(self.OnTimer)
        timer.start(1000)

        self.setLayout(layout)
    def OnModeChanged(self,text):
        mode=QLCDNumber.Mode[text]
        self.lcd.setMode(mode)
        self.parent.OnShowMessage(f'Set Mode:{mode}')
    def OnSegmentStyleChanged(self,text):
        style=QLCDNumber.SegmentStyle[text]
        self.lcd.setSegmentStyle(style)
        self.parent.OnShowMessage(f'Set SegmentStyle:{style}')
    def OnDigitCountChanged(self):
        count=int(self.count.text())
        self.lcd.setDigitCount(count)
        self.parent.OnShowMessage(f'Set DigitCount:{count}')
    def OnDisplayTextChanged(self):
        display=self.text.text()
        self.lcd.display(display)
        self.parent.OnShowMessage(f'Display:{display}')
    def OnTimer(self):
        self.timelcd.display(QDateTime().currentDateTime().toString('yyyy-MM-dd HH:mm:ss'))
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet